<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
require_once __DIR__ . "/Common.php";
$bucket = Common::getBucketName();
$ossClient = Common::getOssClient();
if(is_null($ossClient)) {
    exit(1);
}
$result = $ossClient->putObject($bucket, "b.file", "hi, oss");
Common::println("b.file is created");
Common::println($result["x-oss-request-id"]);
Common::println($result["etag"]);
Common::println($result["content-md5"]);
Common::println($result["body"]);
$result = $ossClient->uploadFile($bucket, "c.file", __FILE__);
Common::println("c.file is created");
Common::println("b.file is created");
Common::println($result["x-oss-request-id"]);
Common::println($result["etag"]);
Common::println($result["content-md5"]);
Common::println($result["body"]);
$content = $ossClient->getObject($bucket, "b.file");
Common::println("b.file is fetched, the content is: " . $content);
$options = [OSS\OssClient::OSS_FILE_DOWNLOAD => "./c.file.localcopy"];
$ossClient->getObject($bucket, "c.file", $options);
Common::println("b.file is fetched to the local file: c.file.localcopy");
Common::println("b.file is created");
$result = $ossClient->copyObject($bucket, "c.file", $bucket, "c.file.copy");
Common::println("lastModifiedTime: " . $result[0]);
Common::println("ETag: " . $result[1]);
$doesExist = $ossClient->doesObjectExist($bucket, "c.file.copy");
Common::println("file c.file.copy exist? " . ($doesExist ? "yes" : "no"));
$result = $ossClient->deleteObject($bucket, "c.file.copy");
Common::println("c.file.copy is deleted");
Common::println("b.file is created");
Common::println($result["x-oss-request-id"]);
$doesExist = $ossClient->doesObjectExist($bucket, "c.file.copy");
Common::println("file c.file.copy exist? " . ($doesExist ? "yes" : "no"));
$result = $ossClient->deleteObjects($bucket, ["b.file", "c.file"]);
foreach ($result as $object) {
    Common::println($object);
}
sleep(2);
unlink("c.file.localcopy");
listObjects($ossClient, $bucket);
listAllObjects($ossClient, $bucket);
createObjectDir($ossClient, $bucket);
putObject($ossClient, $bucket);
uploadFile($ossClient, $bucket);
getObject($ossClient, $bucket);
getObjectToLocalFile($ossClient, $bucket);
copyObject($ossClient, $bucket);
modifyMetaForObject($ossClient, $bucket);
getObjectMeta($ossClient, $bucket);
deleteObject($ossClient, $bucket);
deleteObjects($ossClient, $bucket);
doesObjectExist($ossClient, $bucket);
function createObjectDir($ossClient, $bucket)
{
    try {
        $ossClient->createObjectDir($bucket, "dir");
    } catch (OSS\Core\OssException $e) {
        printf("createObjectDir: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "createObjectDir: OK\n";
}
function putObject($ossClient, $bucket)
{
    $object = "oss-php-sdk-test/upload-test-object-name.txt";
    $content = file_get_contents(__FILE__);
    $options = [];
    try {
        $ossClient->putObject($bucket, $object, $content, $options);
    } catch (OSS\Core\OssException $e) {
        printf("putObject: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "putObject: OK\n";
}
function uploadFile($ossClient, $bucket)
{
    $object = "oss-php-sdk-test/upload-test-object-name.txt";
    $filePath = __FILE__;
    $options = [];
    try {
        $ossClient->uploadFile($bucket, $object, $filePath, $options);
    } catch (OSS\Core\OssException $e) {
        printf("uploadFile: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "uploadFile: OK\n";
}
function listObjects($ossClient, $bucket)
{
    $prefix = "oss-php-sdk-test/";
    $delimiter = "/";
    $nextMarker = "";
    $maxkeys = 1000;
    $options = ["delimiter" => $delimiter, "prefix" => $prefix, "max-keys" => $maxkeys, "marker" => $nextMarker];
    try {
        $listObjectInfo = $ossClient->listObjects($bucket, $options);
    } catch (OSS\Core\OssException $e) {
        printf("listObjects: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "listObjects: OK\n";
    $objectList = $listObjectInfo->getObjectList();
    $prefixList = $listObjectInfo->getPrefixList();
    if(!empty($objectList)) {
        echo "objectList:\n";
        foreach ($objectList as $objectInfo) {
            echo $objectInfo->getKey() . "\n";
        }
    }
    if(!empty($prefixList)) {
        echo "prefixList: \n";
        foreach ($prefixList as $prefixInfo) {
            echo $prefixInfo->getPrefix() . "\n";
        }
    }
}
function listAllObjects($ossClient, $bucket)
{
    $i = 0;
    while ($i < 100) {
        $ossClient->putObject($bucket, "dir/obj" . strval($i), "hi");
        $ossClient->createObjectDir($bucket, "dir/obj" . strval($i));
        $i += 1;
    }
    $prefix = "dir/";
    $delimiter = "/";
    $nextMarker = "";
    $maxkeys = 30;
    while (true) {
        $options = ["delimiter" => $delimiter, "prefix" => $prefix, "max-keys" => $maxkeys, "marker" => $nextMarker];
        var_dump($options);
        try {
            $listObjectInfo = $ossClient->listObjects($bucket, $options);
        } catch (OSS\Core\OssException $e) {
            printf("listAllObjects: FAILED\n");
            printf($e->getMessage() . "\n");
            return NULL;
        }
        $nextMarker = $listObjectInfo->getNextMarker();
        $listObject = $listObjectInfo->getObjectList();
        $listPrefix = $listObjectInfo->getPrefixList();
        var_dump(count($listObject));
        var_dump(count($listPrefix));
        if($nextMarker === "") {
            break;
        }
    }
}
function getObject($ossClient, $bucket)
{
    $object = "oss-php-sdk-test/upload-test-object-name.txt";
    $options = [];
    try {
        $content = $ossClient->getObject($bucket, $object, $options);
    } catch (OSS\Core\OssException $e) {
        printf("getObject: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "getObject: OK\n";
    if(file_get_contents(__FILE__) === $content) {
        echo "getObject: FileContent checked OK\n";
    } else {
        echo "getObject: FileContent checked FAILED\n";
    }
}
function getObjectToLocalFile($ossClient, $bucket)
{
    $object = "oss-php-sdk-test/upload-test-object-name.txt";
    $localfile = "upload-test-object-name.txt";
    $options = [OSS\OssClient::OSS_FILE_DOWNLOAD => $localfile];
    try {
        $ossClient->getObject($bucket, $object, $options);
    } catch (OSS\Core\OssException $e) {
        printf("getObjectToLocalFile: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "getObjectToLocalFile: OK, please check localfile: 'upload-test-object-name.txt'\n";
    if(file_get_contents($localfile) === file_get_contents(__FILE__)) {
        echo "getObjectToLocalFile: FileContent checked OK\n";
    } else {
        echo "getObjectToLocalFile: FileContent checked FAILED\n";
    }
    if(file_exists($localfile)) {
        unlink($localfile);
    }
}
function copyObject($ossClient, $bucket)
{
    $fromBucket = $bucket;
    $fromObject = "oss-php-sdk-test/upload-test-object-name.txt";
    $toBucket = $bucket;
    $toObject = $fromObject . ".copy";
    $options = [];
    try {
        $ossClient->copyObject($fromBucket, $fromObject, $toBucket, $toObject, $options);
    } catch (OSS\Core\OssException $e) {
        printf("copyObject: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "copyObject: OK\n";
}
function modifyMetaForObject($ossClient, $bucket)
{
    $fromBucket = $bucket;
    $fromObject = "oss-php-sdk-test/upload-test-object-name.txt";
    $toBucket = $bucket;
    $toObject = $fromObject;
    $copyOptions = [OSS\OssClient::OSS_HEADERS => ["Cache-Control" => "max-age=60", "Content-Disposition" => "attachment; filename=\"xxxxxx\""]];
    try {
        $ossClient->copyObject($fromBucket, $fromObject, $toBucket, $toObject, $copyOptions);
    } catch (OSS\Core\OssException $e) {
        printf("modifyMetaForObject: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "modifyMetaForObject: OK\n";
}
function getObjectMeta($ossClient, $bucket)
{
    $object = "oss-php-sdk-test/upload-test-object-name.txt";
    try {
        $objectMeta = $ossClient->getObjectMeta($bucket, $object);
    } catch (OSS\Core\OssException $e) {
        printf("getObjectMeta: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "getObjectMeta: OK\n";
    if(isset($objectMeta[strtolower("Content-Disposition")]) && "attachment; filename=\"xxxxxx\"" === $objectMeta[strtolower("Content-Disposition")]) {
        echo "getObjectMeta: ObjectMeta checked OK\n";
    } else {
        echo "getObjectMeta: ObjectMeta checked FAILED\n";
    }
}
function deleteObject($ossClient, $bucket)
{
    $object = "oss-php-sdk-test/upload-test-object-name.txt";
    try {
        $ossClient->deleteObject($bucket, $object);
    } catch (OSS\Core\OssException $e) {
        printf("deleteObject: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "deleteObject: OK\n";
}
function deleteObjects($ossClient, $bucket)
{
    $objects = [];
    $objects[] = "oss-php-sdk-test/upload-test-object-name.txt";
    $objects[] = "oss-php-sdk-test/upload-test-object-name.txt.copy";
    try {
        $ossClient->deleteObjects($bucket, $objects);
    } catch (OSS\Core\OssException $e) {
        printf("deleteObjects: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "deleteObjects: OK\n";
}
function doesObjectExist($ossClient, $bucket)
{
    $object = "oss-php-sdk-test/upload-test-object-name.txt";
    try {
        $exist = $ossClient->doesObjectExist($bucket, $object);
    } catch (OSS\Core\OssException $e) {
        printf("doesObjectExist: FAILED\n");
        printf($e->getMessage() . "\n");
        return NULL;
    }
    echo "doesObjectExist: OK\n";
    var_dump($exist);
}

?>